<include file="public:header" />
    <div class="toptip">
        <div class="toptit">提示：</div>
        <p>非专业人员不得修改菜单信息。</p>
        <p>删除顶级菜单将会自动删除此菜单下的子菜单。</p>
    </div>
	<div class="seltpye_x">
        <div class="left">菜单类型</div>    
        <div class="right">
	        <a href="{:P(array('type'=>''))}" <if condition="$Think.get.type eq ''">class="select"</if>>全部</a>
	        <a href="{:P(array('type'=>1))}" <if condition="$Think.get.type eq 1">class="select"</if>>只显示菜单</a>
        <div class="clear"></div>
        </div>
        <div class="clear"></div>
    </div>

    <form id="form1" name="form1" method="post" action="{:U('menuAllSave')}">
        <div class="list_th">
            <div class="td" style=" width:60%;">
                <div class="left_padding">系统菜单</div>
            </div>
            <div class="td" style=" width:20%;">排序</div>
            <div class="td" style=" width:20%;">
                <div class="list_right">操作</div>
            </div>
            <div class="clear"></div>
        </div>
        <volist name="menu_list" id="menu">
            <div class="list_tr link_bk">
                <div class="td" style=" width:60%;">
                    <div class="category_img J_show" id="{$menu.id}" level="1"></div>
                    <div class="category_input">
                        <input name="save_id[]" type="hidden" value="{$menu.id}"/>
                        <input name="name[]" type="text" class="input_text_default small" maxlength="20" value="{$menu.name}" style=" width: 120px;"/>
                        <span style="color:#999999; margin-left: 5px; font-size: 13px;">(id:<strong>{$menu.id}</strong>controller:<strong>{$menu.controller_name}</strong>action:<strong>{$menu.action_name}</strong>)</span>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="td" style=" width:20%;">
                    <input name="ordid[]" type="text" class="input_text_default small" maxlength="3" value="{$menu.ordid|default="0"}" style="width:50px;"/>
                </div>
                <div class="td edit" style=" width:20%;">
                    <div class="list_right btn">
                        <a href="{:U('menu/add',array('pid'=>$menu['id']))}">此类下加子类</a>
                        <a href="{:U('menu/edit',array('id'=>$menu['id']))}">修改</a>
                        <a href="{:U('menu/delete',array('id'=>$menu['id']))}" class="gray" onclick="return confirm('你确定要删除吗？')">删除</a>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </volist>
        <div class="list_tr">
            <div class="td" style="width: 60%;">
                <div class="J_add category_list_add" level="1" parentid="0">添加顶级分类</div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="list_foot">
            <div class="btnbox">
                <input name="ButSave" type="submit" class="admin_submit" id="ButSave" value="保存分类"/>
                <input name="ButADD" type="button" class="admin_submit" id="ButADD" value="添加分类"  onclick="window.location='{:U('menu/add')}'"/>
            </div>
            <div class="footso"></div>
        </div>
</form>
</div>
<include file="public:footer" />
<script type="text/javascript">
    $(document).ready(function(){
        var Maxlevel=5;//最多分类层数
        var menu_type = "{$Think.get.type}";
        //打开子菜单
        $(".J_show").live('click',function() {
          var sub_box = $(this).closest(".list_tr").next('.j_smalldiv');
          var level = $(this).attr('level');
          sub_box.is(':visible') ? $(this).removeClass("show") : $(this).addClass("show");
          if (sub_box.length == 0 && level < Maxlevel) {
            get_menu($(this).attr('id'), $(this).closest(".list_tr"), level);
          }
          else {
            sub_box.toggle();
          }
        })
      //生成分类
      function get_menu(pid,thisobj,level)
      {
        var tsTimeStamp= new Date().getTime();
        $.getJSON("{:U('menu/index')}", {"pid":pid,'type':menu_type},function(result){
            if (result.status==1){
              var html="";
              var leftbg="";
              var i=1;
              level++;
              for (x in result.data)
              {
                html += "<div class=\"list_tr link_bk\">";
                html += "<div class=\"td\" style=\"width:60%\">";
                html += "<div class=\"category_sub_img l" + level + "\">&nbsp;</div>";
                html += "<div class=\"category_img J_show\" id=\"" + result.data[x]['id'] + "\" level=\"" + level +"\"></div>";
                html += "<div class=\"category_input\">";
                html += "<input name=\"save_id[]\" type=\"hidden\" value=\"" + result.data[x]['id'] + "\"/>";
                html += "<input name=\"categoryname[]\" type=\"text\" value=\"" + result.data[x]['name'] + "\" class=\"input_text_default small\" maxlength=\"20\" style=\"width: 120px;\"/>";
                html += "<span style=\"color:#999999; margin-left: 5px; font-size: 13px;\">(id:<strong>"+result.data[x]['id']+"</strong>controller:<strong>"+result.data[x]['controller_name']+"</strong>action:<strong>"+result.data[x]['action_name']+"</strong>)</span>";
                html += "</div>";
                html += "<div class=\"clear\"></div>";
                html += "</div>";
                html += "<div class=\"td\" style=\"width:20%\"><input name=\"ordid[]\" type=\"text\"  value=\"" + result.data[x]['ordid'] + "\" class=\"input_text_default small\" maxlength=\"3\" style=\"width: 50px;\"/></div>";
                html += "<div class=\"td edit\" style=\"width:20%\"><div class=\"list_right btn\">";
                if (level < Maxlevel) {
                  html += "<a href=\"{:U('menu/add')}&pid=" + result.data[x]['id'] + "\">此类下添加子类</a>";
                }
                html += "<a href=\"{:U('menu/edit')}&id=" + result.data[x]['id'] + "\">修改</a>";
                html += "<a onclick=\"return confirm('你确定要删除吗？')\" href=\"{:U('menu/delete')}&id=" + result.data[x]['id'] + "\" class=\"gray\">删除</a>";
                html += "</div></div>";
                html += "<div class=\"clear\"></div>";
                html += "</div>";
                i++;
              }
              if (level <= Maxlevel) {
                html += "<div class=\"list_tr\"><div class=\"td\" style=\"width:60%;\"><div class=\"category_sub_img last l" + level + "\">&nbsp;</div><div class=\"J_add category_list_add\" level=\"" + level + "\" parentid=\"" + pid + "\">添加分类</div><div class=\"clear\"></div></div></div>";
              }
              thisobj.after('<div class="j_smalldiv">' + html + '</div>');
            }
          }
        );
      }
        //添加分类
        $(".J_add").live('click',function() {
          var level=$(this).attr('level');
          var pid=$(this).attr('parentid');
          var html = '';
          html += "<div class=\"list_tr link_bk\">";
          html += "<div class=\"td\" style=\"width:60%\">";
          if (level>1)
          {
            html += "<div class=\"category_sub_img l" + level + "\">&nbsp;</div>";
          }
          html += "<div class=\"category_img J_show\" id=\"\" level=\"" + level +"\"></div>";
          html += "<div class=\"category_input\">";
          html += "<input name=\"add_pid[]\" type=\"hidden\" value=\"" + pid + "\"/>";
          html += "<input name=\"add_name[]\" type=\"text\" value=\"\" class=\"input_text_default small\" maxlength=\"20\" style=\"width: 120px;\"/>";
          html += "</div>";
          html += "<div class=\"clear\"></div>";
          html += "</div>";
          html += "<div class=\"td\" style=\"width:20%\"><input name=\"add_ordid[]\" type=\"text\"  value=\"0\" class=\"input_text_default small\" maxlength=\"3\" style=\"width: 50px;\"/></div>";
          html += "<div class=\"clear\"></div>";
          html += "</div>";
          $(this).parent().parent().before(html);
        })
    })
</script>
</body>
</html>